<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.17"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Zeebe C# Client: The Zeebe C# client documentation</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Zeebe C# Client
   &#160;<span id="projectnumber">0.15.0</span>
   </div>
   <div id="projectbrief">C# Client to communicate with an Zeebe Gateway</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.17 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('index.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="PageDoc"><div class="header">
  <div class="headertitle">
<div class="title">The <a class="el" href="d6/d18/namespaceZeebe.html">Zeebe</a> C# client documentation </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>The <a class="el" href="d6/d18/namespaceZeebe.html">Zeebe</a> C# client to communicate with a <a class="el" href="d6/d18/namespaceZeebe.html">Zeebe</a> gateway/cluster.</p>
<p>The client is a C# wrapper implementation around the <a href="https://github.com/grpc/grpc">GRPC</a> generated client. It makes it possible to communicate with <a class="el" href="d6/d18/namespaceZeebe.html">Zeebe</a> Gateway via the GRPC protocol, see the <a href="https://docs.zeebe.io/">Zeebe documentation</a> for more information about the <a class="el" href="d6/d18/namespaceZeebe.html">Zeebe</a> project.</p>
<p>The Client is available as a <a href="https://www.nuget.org/packages/zb-client/">Nuget package</a>. </p>
<h1><a class="anchor" id="API"></a>
API documentation</h1>
<ul>
<li>
<a class="el" href="d7/dd6/interfaceZeebe_1_1Client_1_1IZeebeClient.html" title="The client to communicate with a Zeebe gateway/cluster.">Zeebe.Client.IZeebeClient</a> </li>
<li>
<a class="el" href="d9/def/namespaceZeebe_1_1Client_1_1Api_1_1Commands.html">Zeebe.Client.Api.Commands</a> </li>
<li>
<a class="el" href="dd/db3/namespaceZeebe_1_1Client_1_1Api_1_1Responses.html">Zeebe.Client.Api.Responses</a> </li>
<li>
<a class="el" href="db/d2d/namespaceZeebe_1_1Client_1_1Api_1_1Worker.html">Zeebe.Client.Api.Worker</a> </li>
</ul>
<h1><a class="anchor" id="Example"></a>
Example</h1>
<div class="fragment"><div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">//    Copyright (c) 2018 camunda services GmbH (info@camunda.com)</span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">//    Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span></div>
<div class="line"><span class="comment">//    you may not use this file except in compliance with the License.</span></div>
<div class="line"><span class="comment">//    You may obtain a copy of the License at</span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">//        http://www.apache.org/licenses/LICENSE-2.0</span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">//    Unless required by applicable law or agreed to in writing, software</span></div>
<div class="line"><span class="comment">//    distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span></div>
<div class="line"><span class="comment">//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span></div>
<div class="line"><span class="comment">//    See the License for the specific language governing permissions and</span></div>
<div class="line"><span class="comment">//    limitations under the License.</span></div>
<div class="line"> </div>
<div class="line"><span class="keyword">using</span> System;</div>
<div class="line"><span class="keyword">using</span> System.IO;</div>
<div class="line"><span class="keyword">using</span> System.Threading;</div>
<div class="line"><span class="keyword">using</span> System.Threading.Tasks;</div>
<div class="line"><span class="keyword">using</span> NLog.Extensions.Logging;</div>
<div class="line"><span class="keyword">using</span> <a class="code" href="d6/d18/namespaceZeebe.html">Zeebe</a>.<a class="code" href="da/d88/namespaceZeebe_1_1Client.html">Client</a>;</div>
<div class="line"><span class="keyword">using</span> <a class="code" href="d6/d18/namespaceZeebe.html">Zeebe</a>.<a class="code" href="da/d88/namespaceZeebe_1_1Client.html">Client</a>.<a class="code" href="d5/df7/namespaceZeebe_1_1Client_1_1Api.html">Api</a>.<a class="code" href="dd/db3/namespaceZeebe_1_1Client_1_1Api_1_1Responses.html">Responses</a>;</div>
<div class="line"><span class="keyword">using</span> <a class="code" href="d6/d18/namespaceZeebe.html">Zeebe</a>.<a class="code" href="da/d88/namespaceZeebe_1_1Client.html">Client</a>.<a class="code" href="d5/df7/namespaceZeebe_1_1Client_1_1Api.html">Api</a>.<a class="code" href="db/d2d/namespaceZeebe_1_1Client_1_1Api_1_1Worker.html">Worker</a>;</div>
<div class="line"> </div>
<div class="line"><span class="keyword">namespace </span>Client.Examples</div>
<div class="line">{</div>
<div class="line">    <span class="keyword">internal</span> <span class="keyword">class </span>Program</div>
<div class="line">    {</div>
<div class="line">        <span class="keyword">private</span> <span class="keyword">static</span> readonly <span class="keywordtype">string</span> DemoProcessPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, <span class="stringliteral">&quot;Resources&quot;</span>, <span class="stringliteral">&quot;demo-process.bpmn&quot;</span>);</div>
<div class="line">        <span class="keyword">private</span> <span class="keyword">static</span> readonly <span class="keywordtype">string</span> ZeebeUrl = <span class="stringliteral">&quot;0.0.0.0:26500&quot;</span>;</div>
<div class="line">        <span class="keyword">private</span> <span class="keyword">static</span> readonly <span class="keywordtype">string</span> WorkflowInstanceVariables = <span class="stringliteral">&quot;{\&quot;a\&quot;:\&quot;123\&quot;}&quot;</span>;</div>
<div class="line">        <span class="keyword">private</span> <span class="keyword">static</span> readonly <span class="keywordtype">string</span> JobType = <span class="stringliteral">&quot;payment-service&quot;</span>;</div>
<div class="line">        <span class="keyword">private</span> <span class="keyword">static</span> readonly <span class="keywordtype">string</span> WorkerName = Environment.MachineName;</div>
<div class="line">        <span class="keyword">private</span> <span class="keyword">static</span> readonly <span class="keywordtype">long</span> WorkCount = 100L;</div>
<div class="line"> </div>
<div class="line">        <span class="keyword">public</span> <span class="keyword">static</span> async Task Main(<span class="keywordtype">string</span>[] args)</div>
<div class="line">        {</div>
<div class="line">            <span class="comment">// create zeebe client</span></div>
<div class="line">            var client = ZeebeClient.Builder()</div>
<div class="line">                .UseLoggerFactory(<span class="keyword">new</span> NLogLoggerFactory())</div>
<div class="line">                .UseGatewayAddress(ZeebeUrl)</div>
<div class="line">                .UsePlainText()</div>
<div class="line">                .Build();</div>
<div class="line"> </div>
<div class="line">            var topology = await client.TopologyRequest()</div>
<div class="line">                .Send();</div>
<div class="line">            Console.WriteLine(topology);</div>
<div class="line">            await client.NewPublishMessageCommand()</div>
<div class="line">                .MessageName(<span class="stringliteral">&quot;csharp&quot;</span>)</div>
<div class="line">                .CorrelationKey(<span class="stringliteral">&quot;wow&quot;</span>)</div>
<div class="line">                .Variables(<span class="stringliteral">&quot;{\&quot;realValue\&quot;:2}&quot;</span>)</div>
<div class="line">                .Send();</div>
<div class="line"> </div>
<div class="line">            <span class="comment">// deploy</span></div>
<div class="line">            var deployResponse = await client.NewDeployCommand()</div>
<div class="line">                .AddResourceFile(DemoProcessPath)</div>
<div class="line">                .Send();</div>
<div class="line"> </div>
<div class="line">            <span class="comment">// create workflow instance</span></div>
<div class="line">            var workflowKey = deployResponse.Workflows[0].WorkflowKey;</div>
<div class="line"> </div>
<div class="line">            var workflowInstance = await client</div>
<div class="line">                .NewCreateWorkflowInstanceCommand()</div>
<div class="line">                .WorkflowKey(workflowKey)</div>
<div class="line">                .Variables(WorkflowInstanceVariables)</div>
<div class="line">                .Send();</div>
<div class="line"> </div>
<div class="line">            await client.NewSetVariablesCommand(workflowInstance.WorkflowInstanceKey).Variables(<span class="stringliteral">&quot;{\&quot;wow\&quot;:\&quot;this\&quot;}&quot;</span>).Local().Send();</div>
<div class="line"> </div>
<div class="line">            <span class="keywordflow">for</span> (var i = 0; i &lt; WorkCount; i++)</div>
<div class="line">            {</div>
<div class="line">                await client</div>
<div class="line">                    .NewCreateWorkflowInstanceCommand()</div>
<div class="line">                    .WorkflowKey(workflowKey)</div>
<div class="line">                    .Variables(WorkflowInstanceVariables)</div>
<div class="line">                    .Send();</div>
<div class="line">            }</div>
<div class="line"> </div>
<div class="line">            <span class="comment">// open job worker</span></div>
<div class="line">            <span class="keyword">using</span> (var signal = <span class="keyword">new</span> EventWaitHandle(<span class="keyword">false</span>, EventResetMode.AutoReset))</div>
<div class="line">            {</div>
<div class="line">                client.NewWorker()</div>
<div class="line">                      .JobType(JobType)</div>
<div class="line">                      .Handler(HandleJob)</div>
<div class="line">                      .MaxJobsActive(5)</div>
<div class="line">                      .Name(WorkerName)</div>
<div class="line">                      .AutoCompletion()</div>
<div class="line">                      .PollInterval(TimeSpan.FromSeconds(1))</div>
<div class="line">                      .Timeout(TimeSpan.FromSeconds(10))</div>
<div class="line">                      .Open();</div>
<div class="line"> </div>
<div class="line">                <span class="comment">// blocks main thread, so that worker can run</span></div>
<div class="line">                signal.WaitOne();</div>
<div class="line">            }</div>
<div class="line">        }</div>
<div class="line"> </div>
<div class="line">        <span class="keyword">private</span> <span class="keyword">static</span> <span class="keywordtype">void</span> HandleJob(IJobClient jobClient, IJob job)</div>
<div class="line">        {</div>
<div class="line">            <span class="comment">// business logic</span></div>
<div class="line">            var jobKey = job.Key;</div>
<div class="line">            Console.WriteLine(<span class="stringliteral">&quot;Handling job: &quot;</span> + job);</div>
<div class="line"> </div>
<div class="line">            <span class="keywordflow">if</span> (jobKey % 3 == 0)</div>
<div class="line">            {</div>
<div class="line">                jobClient.NewCompleteJobCommand(jobKey)</div>
<div class="line">                    .Variables(<span class="stringliteral">&quot;{\&quot;foo\&quot;:2}&quot;</span>)</div>
<div class="line">                    .Send()</div>
<div class="line">                    .GetAwaiter()</div>
<div class="line">                    .GetResult();</div>
<div class="line">            }</div>
<div class="line">            <span class="keywordflow">else</span> <span class="keywordflow">if</span> (jobKey % 2 == 0)</div>
<div class="line">            {</div>
<div class="line">                jobClient.NewFailCommand(jobKey)</div>
<div class="line">                    .Retries(job.Retries - 1)</div>
<div class="line">                    .ErrorMessage(<span class="stringliteral">&quot;Example fail&quot;</span>)</div>
<div class="line">                    .Send()</div>
<div class="line">                    .GetAwaiter()</div>
<div class="line">                    .GetResult();</div>
<div class="line">            }</div>
<div class="line">            <span class="keywordflow">else</span></div>
<div class="line">            {</div>
<div class="line">                <span class="comment">// auto completion</span></div>
<div class="line">            }</div>
<div class="line">        }</div>
<div class="line">    }</div>
<div class="line">}</div>
</div><!-- fragment --> </div></div><!-- PageDoc -->
</div><!-- contents -->
</div><!-- doc-content -->
<div class="ttc" id="anamespaceZeebe_1_1Client_1_1Api_html"><div class="ttname"><a href="d5/df7/namespaceZeebe_1_1Client_1_1Api.html">Zeebe.Client.Api</a></div><div class="ttdef"><b>Definition:</b> IAccessTokenSupplier.cs:3</div></div>
<div class="ttc" id="anamespaceZeebe_html"><div class="ttname"><a href="d6/d18/namespaceZeebe.html">Zeebe</a></div><div class="ttdef"><b>Definition:</b> IAccessTokenSupplier.cs:3</div></div>
<div class="ttc" id="anamespaceZeebe_1_1Client_1_1Api_1_1Worker_html"><div class="ttname"><a href="db/d2d/namespaceZeebe_1_1Client_1_1Api_1_1Worker.html">Zeebe.Client.Api.Worker</a></div><div class="ttdef"><b>Definition:</b> IJobClient.cs:19</div></div>
<div class="ttc" id="anamespaceZeebe_1_1Client_1_1Api_1_1Responses_html"><div class="ttname"><a href="dd/db3/namespaceZeebe_1_1Client_1_1Api_1_1Responses.html">Zeebe.Client.Api.Responses</a></div><div class="ttdef"><b>Definition:</b> IActivateJobsResponse.cs:17</div></div>
<div class="ttc" id="anamespaceZeebe_1_1Client_html"><div class="ttname"><a href="da/d88/namespaceZeebe_1_1Client.html">Zeebe.Client</a></div><div class="ttdef"><b>Definition:</b> IAccessTokenSupplier.cs:3</div></div>
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Tue Jan 28 2020 21:49:16 for Zeebe C# Client by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.17 </li>
  </ul>
</div>
</body>
</html>
